package xjh.him.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.xjh.him.R;
import xjh.him.common.SharedData;
import xjh.him.entity.User;
import xjh.him.util.GlideUtil;

public class HomeMeActivity extends Activity {
    private ImageView meAvatar, meSex;
    private TextView meName, mePhone, meSignature;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_me);
    }

    public void init(View view, Activity activity) {
        User me;
        meAvatar = view.findViewById(R.id.me_avatar);
        meSex = view.findViewById(R.id.me_sex_icon);
        meName = view.findViewById(R.id.me_name);
        mePhone = view.findViewById(R.id.me_phone);
        meSignature = view.findViewById(R.id.me_signature);
        me = SharedData.me;

        GlideUtil.loadImage(view.getContext(), me.getAvatarUrl(), meAvatar, GlideUtil.defaultRoundedAvatarOpt());
        if (me.getSex() != null && me.getSex().equals("女"))
            meSex.setSelected(true);
        meName.setText(me.getName());
        mePhone.setText(mePhone.getText().toString() + me.getPhone());
        meSignature.setText(me.getSignature());

        Button exitLoginBtn = view.findViewById(R.id.me_exit_login);
        exitLoginBtn.setOnClickListener((v) -> {
            Intent intent = new Intent(activity, LoginActivity.class);
            activity.startActivity(intent);
            finish();
        });
    }
}
